from dateutil.parser import parse

from quant import data_utils

BASE_URL = 'https://trade.500.com/jczq/?playid=270&g=2&date=2024-07-18'
HEADERS = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36'}


def run_half(f, leagues, host_wins_more, start, end):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)

        total_count = 0
        ww_count = 0
        ww_ratios = {}
        wd_count = 0
        wd_ratios = {}
        wl_count = 0
        wl_ratios = {}

        dw_count = 0
        dw_ratios = {}
        dd_count = 0
        dd_ratios = {}
        dl_count = 0
        dl_ratios = {}

        lw_count = 0
        lw_ratios = {}
        ld_count = 0
        ld_ratios = {}
        ll_count = 0
        ll_ratios = {}

        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            league = args[3]
            no = args[0]
            dt = args[1]
            rang_num = 0 if (args[5] == "--" or args[5] == "") else int(args[5])

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if host_wins_more:
                if rang_num > 0:
                    continue

            if not host_wins_more:
                if rang_num <= 0:
                    continue

            total_count += 1
            name = args[4]
            half_result = args[9]

            # 半全场统计
            if half_result == '胜胜':
                ww_count += 1
                ww_ratio = args[63]
                if ww_ratio in ww_ratios:
                    ww_ratios[ww_ratio] += 1
                else:
                    ww_ratios[ww_ratio] = 1

            if half_result == '胜平':
                wd_count += 1
                wd_ratio = args[64]
                if wd_ratio in wd_ratios:
                    wd_ratios[wd_ratio] += 1
                else:
                    wd_ratios[wd_ratio] = 1

            if half_result == '胜负':
                wl_count += 1
                wl_ratio = args[64]
                if wl_count in wl_ratios:
                    wl_ratios[wl_ratio] += 1
                else:
                    wl_ratios[wl_ratio] = 1

            if half_result == '平胜':
                dw_count += 1
                dw_ratio = args[63]
                if dw_ratio in dw_ratios:
                    dw_ratios[dw_ratio] += 1
                else:
                    dw_ratios[dw_ratio] = 1

            if half_result == '平平':
                dd_count += 1
                dd_ratio = args[63]
                if dd_ratio in dd_ratios:
                    dd_ratios[dd_ratio] += 1
                else:
                    dd_ratios[dd_ratio] = 1

            if half_result == '平负':
                dl_count += 1
                dl_ratio = args[63]
                if dl_ratio in dl_ratios:
                    dl_ratios[dl_ratio] += 1
                else:
                    dl_ratios[dl_ratio] = 1

            if half_result == '负胜':
                lw_count += 1
                lw_ratio = args[71]
                if lw_ratio in lw_ratios:
                    lw_ratios[lw_ratio] += 1
                else:
                    lw_ratios[lw_ratio] = 1
            if half_result == '负平':
                ld_count += 1
                ld_ratio = args[70]
                if ld_ratio in ld_ratios:
                    ld_ratios[ld_ratio] += 1
                else:
                    ld_ratios[ld_ratio] = 1
            if half_result == '负负':
                ll_count += 1
                ll_ratio = args[71]
                if ll_ratio in ll_ratios:
                    ll_ratios[ll_ratio] += 1
                else:
                    ll_ratios[ll_ratio] = 1

        ww_ratios = sorted(ww_ratios.items(), key=lambda x: float(x[0]))
        wl_ratios = sorted(wl_ratios.items(), key=lambda x: float(x[0]))
        wd_ratios = sorted(wd_ratios.items(), key=lambda x: float(x[0]))

        dw_ratios = sorted(dw_ratios.items(), key=lambda x: float(x[0]))
        dd_ratios = sorted(dd_ratios.items(), key=lambda x: float(x[0]))
        dl_ratios = sorted(dl_ratios.items(), key=lambda x: float(x[0]))

        lw_ratios = sorted(lw_ratios.items(), key=lambda x: float(x[0]))
        ll_ratios = sorted(ll_ratios.items(), key=lambda x: float(x[0]))
        ld_ratios = sorted(ld_ratios.items(), key=lambda x: float(x[0]))
        print(
            f'========== 半全场基础数据 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} 强队在{"左" if host_wins_more else "右"}\n'
            f'胜胜:{ww_count} {ww_ratios} \n'
            f'胜平:{wd_count} {wd_ratios} \n'
            f'胜负:{wl_count} {wl_ratios} \n'
            f'平胜:{dw_count} {dw_ratios} \n'
            f'平平:{dd_count} {dd_ratios} \n'
            f'平负:{dl_count} {dl_ratios} \n'
            f'负胜:{lw_count} {lw_ratios} \n'
            f'负平:{ld_count} {ld_ratios} \n'
            f'负负:{ll_count} {ll_ratios} \n')


def run_goals_num(f, leagues, start, end):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)

        total_count = 0

        goals03_ratios = {}
        goals34_ratios = {}
        goals45_ratios = {}
        goals56_ratios = {}
        goals67_ratios = {}
        goals78_ratios = {}
        goals89_ratios = {}
        goals9p_ratios = {}

        one_goal_ratios = {}

        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            league = args[3]
            no = args[0]
            dt = args[1]
            goal_num = args[8]
            one_goal_ratio = args[45]
            name = args[4]
            half_result = args[9]
            rang_num = 0 if (args[5] == "--" or args[5] == "") else int(args[5])

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if one_goal_ratio == "" or goal_num == "":
                continue

            total_count += 1
            one_goal_ratio = float(args[45])
            # 进球数统计

            # if(one_goal_ratio<3.5):
            #     one_goal_ratio="3.5"

            if (one_goal_ratio in one_goal_ratios):
                if (goal_num in one_goal_ratios[one_goal_ratio]):
                    one_goal_ratios[one_goal_ratio][goal_num] += 1
                else:
                    one_goal_ratios[one_goal_ratio][goal_num] = 1
            else:
                one_goal_ratios[one_goal_ratio] = {goal_num: 1}

            # if(one_goal_ratio==5):
            #     print(line)

            if (one_goal_ratio < 3):
                if (goal_num in goals03_ratios):
                    goals03_ratios[goal_num] += 1
                else:
                    goals03_ratios[goal_num] = 1

            elif (one_goal_ratio < 4 and one_goal_ratio >= 3):
                if (goal_num in goals34_ratios):
                    goals34_ratios[goal_num] += 1
                else:
                    goals34_ratios[goal_num] = 1

            elif (one_goal_ratio < 5 and one_goal_ratio >= 4):
                if (goal_num in goals45_ratios):
                    goals45_ratios[goal_num] += 1
                else:
                    goals45_ratios[goal_num] = 1

            elif (one_goal_ratio < 6 and one_goal_ratio >= 5):
                if (goal_num in goals56_ratios):
                    goals56_ratios[goal_num] += 1
                else:
                    goals56_ratios[goal_num] = 1

            elif (one_goal_ratio < 7 and one_goal_ratio >= 6):
                if (goal_num in goals67_ratios):
                    goals67_ratios[goal_num] += 1
                else:
                    goals67_ratios[goal_num] = 1

            elif (one_goal_ratio < 8 and one_goal_ratio >= 7):
                if (goal_num in goals78_ratios):
                    goals78_ratios[goal_num] += 1
                else:
                    goals78_ratios[goal_num] = 1
            elif (one_goal_ratio < 9 and one_goal_ratio >= 8):
                if (goal_num in goals89_ratios):
                    goals89_ratios[goal_num] += 1
                else:
                    goals89_ratios[goal_num] = 1
            elif (one_goal_ratio >= 9):
                if (goal_num in goals9p_ratios):
                    goals9p_ratios[goal_num] += 1
                else:
                    goals9p_ratios[goal_num] = 1

        goals34_ratios = sorted(goals34_ratios.items(), key=lambda x: float(x[0]))
        goals45_ratios = sorted(goals45_ratios.items(), key=lambda x: float(x[0]))
        goals56_ratios = sorted(goals56_ratios.items(), key=lambda x: float(x[0]))
        goals67_ratios = sorted(goals67_ratios.items(), key=lambda x: float(x[0]))
        goals78_ratios = sorted(goals78_ratios.items(), key=lambda x: float(x[0]))
        goals89_ratios = sorted(goals89_ratios.items(), key=lambda x: float(x[0]))
        goals9p_ratios = sorted(goals9p_ratios.items(), key=lambda x: float(x[0]))
        print(f'========== 进球数基础数据1 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} \n'
              f'1球赔率\n'
              f'0-3 {goals03_ratios} \n'
              f'3-4 {goals34_ratios} \n'
              f'4-5 {goals45_ratios} \n'
              f'5-6 {goals56_ratios} \n'
              f'6-7 {goals67_ratios} \n'
              f'7-8 {goals78_ratios} \n'
              f'8-9 {goals89_ratios} \n'
              f'9-p {goals9p_ratios} \n'
              )

        one_goal_ratios = sorted(one_goal_ratios.items(), key=lambda x: float(x[0]))
        print(f'联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} \n'
              f'1球赔率\n')
        for item in one_goal_ratios:
            counts = sorted(item[1].items(), key=lambda x: float(x[0]))
            s = ""
            for i in counts:
                s += f'{i[0]}球{i[1]}次 '
            print(f'赔率：{item[0]} 次数:{s}')


def run_goals_num2(f, leagues, start, end):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)

        total_count = 0

        one_goal_ratios = {}

        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            league = args[3]
            no = args[0]
            dt = args[1]
            one_goal_ratio = args[45]
            goal_num = args[8]
            name = args[4]
            half_result = args[9]

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if one_goal_ratio == "" or goal_num == "":
                continue

            total_count += 1
            one_goal_ratio = float(one_goal_ratio)

            # 进球数统计

            if (one_goal_ratio <= 3.5):
                one_goal_ratio = "3.5-"
            else:
                step = 50
                for i in range(300, 2000, step):
                    if one_goal_ratio >= float(i / 100) and one_goal_ratio < float((i + step) / 100):
                        one_goal_ratio = f"{float((i) / 100)}-{float((i + step - 1) / 100)}"
                        break

            # if (one_goal_ratio=="5.0-5.99"):
            #     print(f'{args[45]} {goal_num}')

            if (one_goal_ratio in one_goal_ratios):
                one_goal_ratios[one_goal_ratio][goal_num] += 1
            else:
                one_goal_ratios[one_goal_ratio] = {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0}
                one_goal_ratios[one_goal_ratio][goal_num] += 1

        one_goal_ratios = sorted(one_goal_ratios.items(), key=lambda x: x[0])
        print(f'========== 进球数基础数据2 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count}')
        print(f'            进球数  :0 1 2 3 4 5 6 7  ')
        for item in one_goal_ratios:
            counts = sorted(item[1].items(), key=lambda x: float(x[0]))
            s = ""
            for i in counts:
                s += f'{i[1]} '
            print(f'1球赔率:{item[0]} 次数:{s}')


def run_score(f, leagues, host_wins_more, start, end):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)
        total_count = 0
        score_ratios = {}

        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            no = args[0]
            dt = args[1]
            league = args[3]
            name = args[4]
            goal_num = args[8]
            half_result = args[9]
            one_goal_ratio = args[45]
            rang_num = 0 if (args[5] == "--" or args[5] == "") else int(args[5])
            score_result = args[10]
            score_result = score_result.replace("其他","其它")

            score_10_ratio = args[105]
            score_20_ratio = args[106]
            score_21_ratio = args[107]
            score_30_ratio = args[108]
            score_31_ratio = args[109]
            score_32_ratio = args[110]
            score_40_ratio = args[111]
            score_41_ratio = args[112]
            score_42_ratio = args[113]
            score_50_ratio = args[114]
            score_51_ratio = args[115]
            score_52_ratio = args[116]
            score_90_ratio = args[117]
            score_00_ratio = args[118]
            score_11_ratio = args[119]
            score_22_ratio = args[120]
            score_33_ratio = args[121]
            score_99_ratio = args[122]
            score_01_ratio = args[123]
            score_02_ratio = args[124]
            score_12_ratio = args[125]
            score_03_ratio = args[126]
            score_13_ratio = args[127]
            score_23_ratio = args[128]
            score_04_ratio = args[129]
            score_14_ratio = args[130]
            score_24_ratio = args[131]
            score_05_ratio = args[132]
            score_15_ratio = args[133]
            score_25_ratio = args[134]
            score_09_ratio = args[135]

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if one_goal_ratio == "" or goal_num == "":
                continue

            if host_wins_more:
                if rang_num > 0:
                    continue

            if not host_wins_more:
                if rang_num <= 0:
                    continue

            total_count += 1
            if score_result not in score_ratios:
                score_ratios[score_result] = {}

            if score_result == "1:0":
                if score_10_ratio not in score_ratios["1:0"]:
                    score_ratios["1:0"][score_10_ratio] = 0
                score_ratios["1:0"][score_10_ratio] += 1

            if score_result == "2:0":
                if score_20_ratio not in score_ratios["2:0"]:
                    score_ratios["2:0"][score_20_ratio] = 0
                score_ratios["2:0"][score_20_ratio] += 1

            if score_result == "2:1":
                if score_21_ratio not in score_ratios["2:1"]:
                    score_ratios["2:1"][score_21_ratio] = 0
                score_ratios["2:1"][score_21_ratio] += 1

            if score_result == "3:0":
                if score_30_ratio not in score_ratios["3:0"]:
                    score_ratios["3:0"][score_30_ratio] = 0
                score_ratios["3:0"][score_30_ratio] += 1

            if score_result == "3:1":
                if score_31_ratio not in score_ratios["3:1"]:
                    score_ratios["3:1"][score_31_ratio] = 0
                score_ratios["3:1"][score_31_ratio] += 1

            if score_result == "3:2":
                if score_32_ratio not in score_ratios["3:2"]:
                    score_ratios["3:2"][score_32_ratio] = 0
                score_ratios["3:2"][score_32_ratio] += 1

            if score_result == "4:0":
                if score_40_ratio not in score_ratios["4:0"]:
                    score_ratios["4:0"][score_40_ratio] = 0
                score_ratios["4:0"][score_40_ratio] += 1

            if score_result == "4:1":
                if score_41_ratio not in score_ratios["4:1"]:
                    score_ratios["4:1"][score_41_ratio] = 0
                score_ratios["4:1"][score_41_ratio] += 1

            if score_result == "4:2":
                if score_42_ratio not in score_ratios["4:2"]:
                    score_ratios["4:2"][score_42_ratio] = 0
                score_ratios["4:2"][score_42_ratio] += 1

            if score_result == "5:0":
                if score_50_ratio not in score_ratios["5:0"]:
                    score_ratios["5:0"][score_50_ratio] = 0
                score_ratios["5:0"][score_50_ratio] += 1

            if score_result == "5:1":
                if score_51_ratio not in score_ratios["5:1"]:
                    score_ratios["5:1"][score_51_ratio] = 0
                score_ratios["5:1"][score_51_ratio] += 1

            if score_result == "5:2":
                if score_52_ratio not in score_ratios["5:2"]:
                    score_ratios["5:2"][score_52_ratio] = 0
                score_ratios["5:2"][score_52_ratio] += 1

            if score_result == "胜其它":
                if score_90_ratio not in score_ratios["胜其它"]:
                    score_ratios["胜其它"][score_90_ratio] = 0
                score_ratios["胜其它"][score_90_ratio] += 1

            if score_result == "0:0":
                if score_00_ratio not in score_ratios["0:0"]:
                    score_ratios["0:0"][score_00_ratio] = 0
                score_ratios["0:0"][score_00_ratio] += 1

            if score_result == "1:1":
                if score_11_ratio not in score_ratios["1:1"]:
                    score_ratios["1:1"][score_11_ratio] = 0
                score_ratios["1:1"][score_11_ratio] += 1

            if score_result == "2:2":
                if score_22_ratio not in score_ratios["2:2"]:
                    score_ratios["2:2"][score_22_ratio] = 0
                score_ratios["2:2"][score_22_ratio] += 1

            if score_result == "3:3":
                if score_33_ratio not in score_ratios["3:3"]:
                    score_ratios["3:3"][score_33_ratio] = 0
                score_ratios["3:3"][score_33_ratio] += 1

            if score_result == "平其它":
                if score_99_ratio not in score_ratios["平其它"]:
                    score_ratios["平其它"][score_99_ratio] = 0
                score_ratios["平其它"][score_99_ratio] += 1

            if score_result == "0:1":
                if score_01_ratio not in score_ratios["0:1"]:
                    score_ratios["0:1"][score_01_ratio] = 0
                score_ratios["0:1"][score_01_ratio] += 1

            if score_result == "0:2":
                if score_02_ratio not in score_ratios["0:2"]:
                    score_ratios["0:2"][score_02_ratio] = 0
                score_ratios["0:2"][score_02_ratio] += 1

            if score_result == "1:2":
                if score_12_ratio not in score_ratios["1:2"]:
                    score_ratios["1:2"][score_12_ratio] = 0
                score_ratios["1:2"][score_12_ratio] += 1

            if score_result == "0:3":
                if score_03_ratio not in score_ratios["0:3"]:
                    score_ratios["0:3"][score_03_ratio] = 0
                score_ratios["0:3"][score_03_ratio] += 1

            if score_result == "1:3":
                if score_13_ratio not in score_ratios["1:3"]:
                    score_ratios["1:3"][score_13_ratio] = 0
                score_ratios["1:3"][score_13_ratio] += 1

            if score_result == "2:3":
                if score_23_ratio not in score_ratios["2:3"]:
                    score_ratios["2:3"][score_23_ratio] = 0
                score_ratios["2:3"][score_23_ratio] += 1

            if score_result == "0:4":
                if score_04_ratio not in score_ratios["0:4"]:
                    score_ratios["0:4"][score_04_ratio] = 0
                score_ratios["0:4"][score_04_ratio] += 1

            if score_result == "1:4":
                if score_14_ratio not in score_ratios["1:4"]:
                    score_ratios["1:4"][score_14_ratio] = 0
                score_ratios["1:4"][score_14_ratio] += 1

            if score_result == "2:4":
                if score_24_ratio not in score_ratios["2:4"]:
                    score_ratios["2:4"][score_24_ratio] = 0
                score_ratios["2:4"][score_24_ratio] += 1

            if score_result == "0:5":
                if score_05_ratio not in score_ratios["0:5"]:
                    score_ratios["0:5"][score_05_ratio] = 0
                score_ratios["0:5"][score_05_ratio] += 1

            if score_result == "1:5":
                if score_15_ratio not in score_ratios["1:5"]:
                    score_ratios["1:5"][score_15_ratio] = 0
                score_ratios["1:5"][score_15_ratio] += 1

            if score_result == "2:5":
                if score_25_ratio not in score_ratios["2:5"]:
                    score_ratios["2:5"][score_25_ratio] = 0
                score_ratios["2:5"][score_25_ratio] += 1

            if score_result == "负其它":
                if score_09_ratio not in score_ratios["负其它"]:
                    score_ratios["负其它"][score_09_ratio] = 0
                score_ratios["负其它"][score_09_ratio] += 1

        keys = ['1:0', '2:0', '2:1', '3:0', '3:1', '3:2', '4:0', '4:1', '4:2', '5:0', '5:1', '5:2', '胜其它',
                '0:0', '1:1', '2:2', '3:3', '平其它',
                '0:1', '0:2', '1:2', '0:3', '1:3', '2:3', '0:4', '1:4', '2:4', '0:5', '1:5', '2:5', '负其它']
        print(
            f'========== 比分基础数据 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} 强队在{"左" if host_wins_more else "右"} ==========')
        for item in keys:
            if item not in score_ratios.keys():
                continue
            dict = sorted(score_ratios[item].items(), key=lambda d: float(d[0]))
            print(f'比分:{item} 次数:{dict}')


def run_goal_num3(f, leagues, start, end):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)
        total_count = 0
        goal_num_ratios = {"0": {}, "1": {}, "2": {}, "3": {}, "4": {}, "5": {}, "6": {}, "7": {}}

        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            no = args[0]
            dt = args[1]
            league = args[3]
            name = args[4]
            goal_num = args[8]
            half_result = args[9]
            one_goal_ratio = args[45]
            # rang_num = 0 if (args[5] == "--" or args[5] == "") else int(args[5])

            goal_ratio_0 = args[44]
            goal_ratio_1 = args[45]
            goal_ratio_2 = args[46]
            goal_ratio_3 = args[47]
            goal_ratio_4 = args[48]
            goal_ratio_5 = args[49]
            goal_ratio_6 = args[50]
            goal_ratio_7 = args[51]

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if one_goal_ratio == "" or goal_num == "":
                continue

            # if host_wins_more:
            #     if rang_num > 0:
            #         continue
            #
            # if not host_wins_more:
            #     if rang_num <= 0:
            #         continue

            total_count += 1
            if goal_num == "0":
                if goal_ratio_0 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_0] = 0
                goal_num_ratios[goal_num][goal_ratio_0] += 1

            elif goal_num == "1":
                if goal_ratio_1 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_1] = 0
                goal_num_ratios[goal_num][goal_ratio_1] += 1

            elif goal_num == "2":
                if goal_ratio_2 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_2] = 0
                goal_num_ratios[goal_num][goal_ratio_2] += 1

            elif goal_num == "3":
                if goal_ratio_3 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_3] = 0
                goal_num_ratios[goal_num][goal_ratio_3] += 1

            elif goal_num == "4":
                if goal_ratio_4 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_4] = 0
                goal_num_ratios[goal_num][goal_ratio_4] += 1

            elif goal_num == "5":
                if goal_ratio_5 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_5] = 0
                goal_num_ratios[goal_num][goal_ratio_5] += 1

            elif goal_num == "6":
                if goal_ratio_6 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_6] = 0
                goal_num_ratios[goal_num][goal_ratio_6] += 1

            elif goal_num == "7":
                if goal_ratio_7 not in goal_num_ratios[goal_num]:
                    goal_num_ratios[goal_num][goal_ratio_7] = 0
                goal_num_ratios[goal_num][goal_ratio_7] += 1

            else:
                print(line)

        keys = ['0', '1', '2', '3', '4', '5', '6', '7']
        print(
            f'========== 进球数基础数据3 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} ==========')
        for item in keys:
            if item not in goal_num_ratios.keys():
                continue
            dict = sorted(goal_num_ratios[item].items(), key=lambda d: float(d[0]))
            print(f'进球数:{item} 赔率:{dict}')


def query_goal_num_success(f, leagues, start, end, querys):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)
        total_count = 0

        goal_ratio_count = 0
        success_count = 0

        # total count, success count
        goal_num_0_count = [0, 0]
        goal_num_1_count = [0, 0]
        goal_num_2_count = [0, 0]
        goal_num_3_count = [0, 0]
        goal_num_4_count = [0, 0]
        goal_num_5_count = [0, 0]
        goal_num_6_count = [0, 0]
        goal_num_7_count = [0, 0]

        # 进球数赔率命中统计
        # 0,1,2,3,4,5,6,7球
        # 小于query赔率命中的次数,等于query赔率命中的次数，大于query赔率命中的次数
        goal_success_counts = [[0, 0, 0], [0, 0, 0], [0, 0, 0],
                               [0, 0, 0], [0, 0, 0], [0, 0, 0],
                               [0, 0, 0], [0, 0, 0]]

        # 进球数所对应赔率次数统计
        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            no = args[0]
            dt = args[1]
            league = args[3]
            name = args[4]
            goal_num = args[8]
            half_result = args[9]
            one_goal_ratio = args[45]
            # rang_num = 0 if (args[5] == "--" or args[5] == "") else int(args[5])

            goal_ratio_0 = args[44]
            goal_ratio_1 = args[45]
            goal_ratio_2 = args[46]
            goal_ratio_3 = args[47]
            goal_ratio_4 = args[48]
            goal_ratio_5 = args[49]
            goal_ratio_6 = args[50]
            goal_ratio_7 = args[51]

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if one_goal_ratio == "" or goal_num == "" or goal_ratio_0 == "" or goal_ratio_1 == "" or goal_ratio_2 == "" or goal_ratio_3 == "":
                continue

            total_count += 1
            goal_num = int(goal_num)
            goal_ratio_0 = float(goal_ratio_0)
            goal_ratio_1 = float(goal_ratio_1)
            goal_ratio_2 = float(goal_ratio_2)
            goal_ratio_3 = float(goal_ratio_3)
            goal_ratio_4 = float(goal_ratio_4)
            goal_ratio_5 = float(goal_ratio_5)
            goal_ratio_6 = float(goal_ratio_6)
            goal_ratio_7 = float(goal_ratio_7)
            goal_ratios = [goal_ratio_0, goal_ratio_1, goal_ratio_2, goal_ratio_3, goal_ratio_4, goal_ratio_5,
                           goal_ratio_6, goal_ratio_7]

            # if no == "1019177" or no == "1025539":
            #     print(line)

            if (goal_ratios[goal_num] < querys[goal_num]):
                goal_success_counts[goal_num][0] += 1
            elif (goal_ratios[goal_num] == querys[goal_num]):
                goal_success_counts[goal_num][1] += 1
            else:
                goal_success_counts[goal_num][2] += 1

            # 0球
            if querys[0] == goal_ratio_0:
                goal_num_0_count[0] += 1
                if goal_num == 0:
                    goal_num_0_count[1] += 1

            # 1球
            if querys[1] == goal_ratio_1:
                goal_num_1_count[0] += 1
                if goal_num == 1:
                    goal_num_1_count[1] += 1

            # 2球
            if querys[2] == goal_ratio_2:
                goal_num_2_count[0] += 1
                if goal_num == 2:
                    goal_num_2_count[1] += 1

            # 3球
            if querys[3] == goal_ratio_3:
                goal_num_3_count[0] += 1
                if goal_num == 3:
                    goal_num_3_count[1] += 1

            # 4球
            if querys[4] == goal_ratio_4:
                goal_num_4_count[0] += 1
                if goal_num == 4:
                    goal_num_4_count[1] += 1

            # 5球
            if querys[5] == goal_ratio_5:
                goal_num_5_count[0] += 1
                if goal_num == 5:
                    goal_num_5_count[1] += 1

            # 6球
            if querys[6] == goal_ratio_6:
                goal_num_6_count[0] += 1
                if goal_num == 6:
                    goal_num_6_count[1] += 1

            # 7球
            if querys[7] == goal_ratio_7:
                goal_num_7_count[0] += 1
                if goal_num == 7:
                    goal_num_7_count[1] += 1

        print(
            f'========== 进球数命中率 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} ==========')
        print(
            f'0球 赔率:{querys[0]} 出现:{goal_num_0_count[0]}{getStar(goal_num_0_count[0])} 命中:{goal_num_0_count[1]}{getEqual(goal_num_0_count[1])}')
        print(
            f'1球 赔率:{querys[1]} 出现:{goal_num_1_count[0]}{getStar(goal_num_1_count[0])} 命中:{goal_num_1_count[1]}{getEqual(goal_num_1_count[1])}')
        print(
            f'2球 赔率:{querys[2]} 出现:{goal_num_2_count[0]}{getStar(goal_num_2_count[0])} 命中:{goal_num_2_count[1]}{getEqual(goal_num_2_count[1])}')
        print(
            f'3球 赔率:{querys[3]} 出现:{goal_num_3_count[0]}{getStar(goal_num_3_count[0])} 命中:{goal_num_3_count[1]}{getEqual(goal_num_3_count[1])}')
        print(
            f'4球 赔率:{querys[4]} 出现:{goal_num_4_count[0]}{getStar(goal_num_4_count[0])} 命中:{goal_num_4_count[1]}{getEqual(goal_num_4_count[1])}')
        print(
            f'5球 赔率:{querys[5]} 出现:{goal_num_5_count[0]}{getStar(goal_num_5_count[0])} 命中:{goal_num_5_count[1]}{getEqual(goal_num_5_count[1])}')
        print(
            f'6球 赔率:{querys[6]} 出现:{goal_num_6_count[0]}{getStar(goal_num_6_count[0])} 命中:{goal_num_6_count[1]}{getEqual(goal_num_6_count[1])}')
        print(
            f'7球 赔率:{querys[7]} 出现:{goal_num_7_count[0]}{getStar(goal_num_7_count[0])} 命中:{goal_num_7_count[1]}{getEqual(goal_num_7_count[1])}')

        names = ['0球', '1球', '2球', '3球', '4球', '5球', '6球', '7球']
        print(f'===== 分析 ===== ')
        for i in range(0, 8):
            name = names[i]
            query = querys[i]
            count = goal_success_counts[i]
            print(f'{name} 当前数据:{query} 小于|等于|大于 {count[0]}|{count[1]}|{count[2]} '
                  f'|{0 if count[0] == 0 else getMinus(count[0])}|{0 if count[1] == 0 else getEqual(count[1])}|{0 if count[2] == 0 else getPlus(count[2])}|')


def query_half_success(f, leagues, start, end, is_home_team_rang_qiu, querys):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)

        total_count = 0
        ww_count = 0
        ww_ratios = {}
        wd_count = 0
        wd_ratios = {}
        wl_count = 0
        wl_ratios = {}

        dw_count = 0
        dw_ratios = {}
        dd_count = 0
        dd_ratios = {}
        dl_count = 0
        dl_ratios = {}

        lw_count = 0
        lw_ratios = {}
        ld_count = 0
        ld_ratios = {}
        ll_count = 0
        ll_ratios = {}

        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            league = args[3]
            no = args[0]
            dt = args[1]
            rang_num = 0 if (args[5] == "--" or args[5] == "") else int(args[5])

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if is_home_team_rang_qiu:
                if rang_num > 0:
                    continue

            if not is_home_team_rang_qiu:
                if rang_num <= 0:
                    continue

            total_count += 1
            name = args[4]
            half_result = args[9]

            # 半全场统计
            if half_result == '胜胜':
                ww_count += 1
                ww_ratio = args[63]
                if ww_ratio in ww_ratios:
                    ww_ratios[ww_ratio] += 1
                else:
                    ww_ratios[ww_ratio] = 1

            if half_result == '胜平':
                wd_count += 1
                wd_ratio = args[64]
                if wd_ratio in wd_ratios:
                    wd_ratios[wd_ratio] += 1
                else:
                    wd_ratios[wd_ratio] = 1

            if half_result == '胜负':
                wl_count += 1
                wl_ratio = args[64]
                if wl_count in wl_ratios:
                    wl_ratios[wl_ratio] += 1
                else:
                    wl_ratios[wl_ratio] = 1

            if half_result == '平胜':
                dw_count += 1
                dw_ratio = args[63]
                if dw_ratio in dw_ratios:
                    dw_ratios[dw_ratio] += 1
                else:
                    dw_ratios[dw_ratio] = 1

            if half_result == '平平':
                dd_count += 1
                dd_ratio = args[63]
                if dd_ratio in dd_ratios:
                    dd_ratios[dd_ratio] += 1
                else:
                    dd_ratios[dd_ratio] = 1

            if half_result == '平负':
                dl_count += 1
                dl_ratio = args[63]
                if dl_ratio in dl_ratios:
                    dl_ratios[dl_ratio] += 1
                else:
                    dl_ratios[dl_ratio] = 1

            if half_result == '负胜':
                lw_count += 1
                lw_ratio = args[71]
                if lw_ratio in lw_ratios:
                    lw_ratios[lw_ratio] += 1
                else:
                    lw_ratios[lw_ratio] = 1
            if half_result == '负平':
                ld_count += 1
                ld_ratio = args[70]
                if ld_ratio in ld_ratios:
                    ld_ratios[ld_ratio] += 1
                else:
                    ld_ratios[ld_ratio] = 1
            if half_result == '负负':
                ll_count += 1
                ll_ratio = args[71]
                if ll_ratio in ll_ratios:
                    ll_ratios[ll_ratio] += 1
                else:
                    ll_ratios[ll_ratio] = 1

        ww_ratios = sorted(ww_ratios.items(), key=lambda x: float(x[0]))
        wl_ratios = sorted(wl_ratios.items(), key=lambda x: float(x[0]))
        wd_ratios = sorted(wd_ratios.items(), key=lambda x: float(x[0]))

        dw_ratios = sorted(dw_ratios.items(), key=lambda x: float(x[0]))
        dd_ratios = sorted(dd_ratios.items(), key=lambda x: float(x[0]))
        dl_ratios = sorted(dl_ratios.items(), key=lambda x: float(x[0]))

        lw_ratios = sorted(lw_ratios.items(), key=lambda x: float(x[0]))
        ll_ratios = sorted(ll_ratios.items(), key=lambda x: float(x[0]))
        ld_ratios = sorted(ld_ratios.items(), key=lambda x: float(x[0]))
        print(
            f'===== 半全场命中率 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} 强队在{"左" if is_home_team_rang_qiu else "右"}\n'
            f'胜胜:{ww_count} {ww_ratios} \n'
            f'胜平:{wd_count} {wd_ratios} \n'
            f'胜负:{wl_count} {wl_ratios} \n'
            f'平胜:{dw_count} {dw_ratios} \n'
            f'平平:{dd_count} {dd_ratios} \n'
            f'平负:{dl_count} {dl_ratios} \n'
            f'负胜:{lw_count} {lw_ratios} \n'
            f'负平:{ld_count} {ld_ratios} \n'
            f'负负:{ll_count} {ll_ratios}')

        # 胜胜 胜平 胜负
        # 平胜 平平 平负
        # 负胜 负平 负负
        # 小于的次数，等于的次数，大于的次数
        counts = [[0, 0, 0], [0, 0, 0], [0, 0, 0]
            , [0, 0, 0], [0, 0, 0], [0, 0, 0]
            , [0, 0, 0], [0, 0, 0], [0, 0, 0]]

        data_ratios = [ww_ratios, wd_ratios, wl_ratios, dw_ratios, dd_ratios, dl_ratios, lw_ratios, ld_ratios,
                       ll_ratios]
        names = ['胜胜', '胜平', '胜负', '平胜', '平平', '平负', '负胜', '负平', '负负']
        for i in range(0, 9):
            name = names[i]
            ratios = data_ratios[i]
            query = querys[i]
            for item in ratios:
                if (float(item[0]) < query):
                    counts[i][0] += item[1]
                elif (float(item[0]) == query):
                    counts[i][1] += item[1]
                else:
                    counts[i][2] += item[1]

        print(f'===== 分析 ===== ')
        for i in range(0, 9):
            name = names[i]
            query = querys[i]
            count = counts[i]
            print(f'{name} 当前数据:{query} 小于|等于|大于 {count[0]}|{count[1]}|{count[2]} '
                  f'|{0 if count[0] == 0 else getMinus(count[0])}|{0 if count[1] == 0 else getEqual(count[1])}|{0 if count[2] == 0 else getPlus(count[2])}|')


def query_score_success(f, leagues, start, end, is_home_rang_qiu, querys):
    with open(f, "r", encoding='utf-8') as file:
        line_count = 0
        start_line = 2
        start_date = parse(start)
        end_date = parse(end)
        total_count = 0
        score_ratios = {}

        for line in file:
            line_count += 1
            if (line_count <= start_line):
                continue

            args = line.split(',')
            no = args[0]
            dt = args[1]
            league = args[3]
            name = args[4]
            goal_num = args[8]
            half_result = args[9]
            one_goal_ratio = args[45]
            rang_num = 0 if (args[5] == "--" or args[5] == "") else int(args[5])
            score_result = args[10]
            score_result = score_result.replace("其他","其它")

            score_10_ratio = args[105]
            score_20_ratio = args[106]
            score_21_ratio = args[107]
            score_30_ratio = args[108]
            score_31_ratio = args[109]
            score_32_ratio = args[110]
            score_40_ratio = args[111]
            score_41_ratio = args[112]
            score_42_ratio = args[113]
            score_50_ratio = args[114]
            score_51_ratio = args[115]
            score_52_ratio = args[116]
            score_90_ratio = args[117]
            score_00_ratio = args[118]
            score_11_ratio = args[119]
            score_22_ratio = args[120]
            score_33_ratio = args[121]
            score_99_ratio = args[122]
            score_01_ratio = args[123]
            score_02_ratio = args[124]
            score_12_ratio = args[125]
            score_03_ratio = args[126]
            score_13_ratio = args[127]
            score_23_ratio = args[128]
            score_04_ratio = args[129]
            score_14_ratio = args[130]
            score_24_ratio = args[131]
            score_05_ratio = args[132]
            score_15_ratio = args[133]
            score_25_ratio = args[134]
            score_09_ratio = args[135]

            date = parse(dt)
            if (date < start_date):
                continue

            if (date > end_date):
                break

            if league not in leagues:
                continue

            if one_goal_ratio == "" or goal_num == "":
                continue

            if is_home_rang_qiu:
                if rang_num > 0:
                    continue

            if not is_home_rang_qiu:
                if rang_num <= 0:
                    continue

            total_count += 1
            if score_result not in score_ratios:
                score_ratios[score_result] = {}

            if score_result == "1:0":
                if score_10_ratio not in score_ratios["1:0"]:
                    score_ratios["1:0"][score_10_ratio] = 0
                score_ratios["1:0"][score_10_ratio] += 1

            if score_result == "2:0":
                if score_20_ratio not in score_ratios["2:0"]:
                    score_ratios["2:0"][score_20_ratio] = 0
                score_ratios["2:0"][score_20_ratio] += 1

            if score_result == "2:1":
                if score_21_ratio not in score_ratios["2:1"]:
                    score_ratios["2:1"][score_21_ratio] = 0
                score_ratios["2:1"][score_21_ratio] += 1

            if score_result == "3:0":
                if score_30_ratio not in score_ratios["3:0"]:
                    score_ratios["3:0"][score_30_ratio] = 0
                score_ratios["3:0"][score_30_ratio] += 1

            if score_result == "3:1":
                if score_31_ratio not in score_ratios["3:1"]:
                    score_ratios["3:1"][score_31_ratio] = 0
                score_ratios["3:1"][score_31_ratio] += 1

            if score_result == "3:2":
                if score_32_ratio not in score_ratios["3:2"]:
                    score_ratios["3:2"][score_32_ratio] = 0
                score_ratios["3:2"][score_32_ratio] += 1

            if score_result == "4:0":
                if score_40_ratio not in score_ratios["4:0"]:
                    score_ratios["4:0"][score_40_ratio] = 0
                score_ratios["4:0"][score_40_ratio] += 1

            if score_result == "4:1":
                if score_41_ratio not in score_ratios["4:1"]:
                    score_ratios["4:1"][score_41_ratio] = 0
                score_ratios["4:1"][score_41_ratio] += 1

            if score_result == "4:2":
                if score_42_ratio not in score_ratios["4:2"]:
                    score_ratios["4:2"][score_42_ratio] = 0
                score_ratios["4:2"][score_42_ratio] += 1

            if score_result == "5:0":
                if score_50_ratio not in score_ratios["5:0"]:
                    score_ratios["5:0"][score_50_ratio] = 0
                score_ratios["5:0"][score_50_ratio] += 1

            if score_result == "5:1":
                if score_51_ratio not in score_ratios["5:1"]:
                    score_ratios["5:1"][score_51_ratio] = 0
                score_ratios["5:1"][score_51_ratio] += 1

            if score_result == "5:2":
                if score_52_ratio not in score_ratios["5:2"]:
                    score_ratios["5:2"][score_52_ratio] = 0
                score_ratios["5:2"][score_52_ratio] += 1

            if score_result == "胜其它":
                if score_90_ratio not in score_ratios["胜其它"]:
                    score_ratios["胜其它"][score_90_ratio] = 0
                score_ratios["胜其它"][score_90_ratio] += 1

            if score_result == "0:0":
                if score_00_ratio not in score_ratios["0:0"]:
                    score_ratios["0:0"][score_00_ratio] = 0
                score_ratios["0:0"][score_00_ratio] += 1

            if score_result == "1:1":
                if score_11_ratio not in score_ratios["1:1"]:
                    score_ratios["1:1"][score_11_ratio] = 0
                score_ratios["1:1"][score_11_ratio] += 1

            if score_result == "2:2":
                if score_22_ratio not in score_ratios["2:2"]:
                    score_ratios["2:2"][score_22_ratio] = 0
                score_ratios["2:2"][score_22_ratio] += 1

            if score_result == "3:3":
                if score_33_ratio not in score_ratios["3:3"]:
                    score_ratios["3:3"][score_33_ratio] = 0
                score_ratios["3:3"][score_33_ratio] += 1

            if score_result == "平其它":
                if score_99_ratio not in score_ratios["平其它"]:
                    score_ratios["平其它"][score_99_ratio] = 0
                score_ratios["平其它"][score_99_ratio] += 1

            if score_result == "0:1":
                if score_01_ratio not in score_ratios["0:1"]:
                    score_ratios["0:1"][score_01_ratio] = 0
                score_ratios["0:1"][score_01_ratio] += 1

            if score_result == "0:2":
                if score_02_ratio not in score_ratios["0:2"]:
                    score_ratios["0:2"][score_02_ratio] = 0
                score_ratios["0:2"][score_02_ratio] += 1

            if score_result == "1:2":
                if score_12_ratio not in score_ratios["1:2"]:
                    score_ratios["1:2"][score_12_ratio] = 0
                score_ratios["1:2"][score_12_ratio] += 1

            if score_result == "0:3":
                if score_03_ratio not in score_ratios["0:3"]:
                    score_ratios["0:3"][score_03_ratio] = 0
                score_ratios["0:3"][score_03_ratio] += 1

            if score_result == "1:3":
                if score_13_ratio not in score_ratios["1:3"]:
                    score_ratios["1:3"][score_13_ratio] = 0
                score_ratios["1:3"][score_13_ratio] += 1

            if score_result == "2:3":
                if score_23_ratio not in score_ratios["2:3"]:
                    score_ratios["2:3"][score_23_ratio] = 0
                score_ratios["2:3"][score_23_ratio] += 1

            if score_result == "0:4":
                if score_04_ratio not in score_ratios["0:4"]:
                    score_ratios["0:4"][score_04_ratio] = 0
                score_ratios["0:4"][score_04_ratio] += 1

            if score_result == "1:4":
                if score_14_ratio not in score_ratios["1:4"]:
                    score_ratios["1:4"][score_14_ratio] = 0
                score_ratios["1:4"][score_14_ratio] += 1

            if score_result == "2:4":
                if score_24_ratio not in score_ratios["2:4"]:
                    score_ratios["2:4"][score_24_ratio] = 0
                score_ratios["2:4"][score_24_ratio] += 1

            if score_result == "0:5":
                if score_05_ratio not in score_ratios["0:5"]:
                    score_ratios["0:5"][score_05_ratio] = 0
                score_ratios["0:5"][score_05_ratio] += 1

            if score_result == "1:5":
                if score_15_ratio not in score_ratios["1:5"]:
                    score_ratios["1:5"][score_15_ratio] = 0
                score_ratios["1:5"][score_15_ratio] += 1

            if score_result == "2:5":
                if score_25_ratio not in score_ratios["2:5"]:
                    score_ratios["2:5"][score_25_ratio] = 0
                score_ratios["2:5"][score_25_ratio] += 1

            if score_result == "负其它":
                if score_09_ratio not in score_ratios["负其它"]:
                    score_ratios["负其它"][score_09_ratio] = 0
                score_ratios["负其它"][score_09_ratio] += 1

        keys = ['1:0', '2:0', '2:1', '3:0', '3:1', '3:2', '4:0', '4:1', '4:2', '5:0', '5:1', '5:2', '胜其它',
                '0:0', '1:1', '2:2', '3:3', '平其它',
                '0:1', '0:2', '1:2', '0:3', '1:3', '2:3', '0:4', '1:4', '2:4', '0:5', '1:5', '2:5', '负其它']
        counts = []
        for i in range(0, len(keys)):
            counts.append([0, 0, 0])

        print(
            f'========== 比分命中率 联赛:{leagues} 时间:{start} - {end} 总场次:{total_count} 强队在{"左" if is_home_rang_qiu else "右"} ==========')
        for item in keys:
            if item not in score_ratios.keys():
                continue
            dict = sorted(score_ratios[item].items(), key=lambda d: float(d[0]))
            print(f'比分:{item} 次数:{dict}')

        # 分析次数分布
        print("===== 分析 =====")
        for i in range(0, len(keys)):
            key = keys[i]
            if (key not in score_ratios):
                score_ratios[key] = {}
            ratios = score_ratios[key]
            for item in ratios.items():
                if (float(item[0]) < float(querys[key])):
                    counts[i][0] += item[1]
                elif float(item[0]) == float(querys[key]):
                    counts[i][1] += item[1]
                else:
                    counts[i][2] += item[1]

        for i in range(0, len(keys)):
            key = keys[i]
            query = querys[key]
            count = counts[i]
            print(f'{key} 当前数据:{query} 小于|等于|大于 {count[0]}|{count[1]}|{count[2]} '
                  f'|{0 if count[0] == 0 else getMinus(count[0])}|{0 if count[1] == 0 else getEqual(count[1])}|{0 if count[2] == 0 else getPlus(count[2])}|')


def getStar(count):
    s = ""
    for i in range(0, count):
        s += "*"
    return s


def getEqual(count):
    s = ""
    for i in range(0, count):
        s += "="
    return s


def getMinus(count):
    s = ""
    for i in range(0, count):
        s += "-"
    return s


def getPlus(count):
    s = ""
    for i in range(0, count):
        s += "+"
    return s


start = '2023/01/01'
end = '2024/08/01'
# leagues = ['韩职', '韩足总杯']
leagues = ['瑞超']
f = "./data/20240808.csv"
# host_wins_more = True
# run_half(f, leagues, host_wins_more, start, end)
# #
# host_wins_more = False
# run_half(f, leagues, host_wins_more, start, end)
# run_goals_num(f, leagues, start, end)
# run_goals_num2(f, leagues, start, end)
# #
# host_wins_more = True
# run_score(f, leagues, host_wins_more, start, end)
#
# host_wins_more = False
# run_score(f, leagues, host_wins_more, start, end)
# run_goal_num3(f, leagues, start, end)

day = -1
math_goal_ratios = data_utils.read_goal_ratio(day)
half_ratios = data_utils.read_half_ratios(day)
score_ratios = data_utils.read_score_ratios(day)
is_home_team_rang_qiu = {"4101": False, "4102": True, "4103": True,
                         "5001": False, "5002": True,
                         "6001":True,"6002":True,"6003":True,"6004":True,"6005":True,
                         "6006":True,"6007":True,"6008":True,"6009":True,"6010":False,
                         "6011":True,"1001":True,"5004":True,"1002":True}
# matches = ["6001","6002","6003","6004","6005","6006","6007","6008","6009"]
matches = ["1002"]
for match in matches:
    print(f"\n====== 读取{match}进球数命中率 ======")
    query_goal_num_success(f, leagues, start, end, math_goal_ratios[match])
    print(f"\n====== 读取{match}半全场数命中率 ======")
    query_half_success(f, leagues, start, end, is_home_team_rang_qiu[match], half_ratios[match])
    print(f"\n====== 读取{match}比分数命中率 ======")
    query_score_success(f, leagues, start, end, is_home_team_rang_qiu[match], score_ratios[match])